﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Orion.Lib
{
    public class Ship : GraphicElement
    {
        List<IWeapon> weaponItems = new List<IWeapon>();
        public Ship(Texture2D text)
            : base(text)
        {
            
        }

        public void AttachWeapon(IWeapon weap)
        {
            weaponItems.Add(weap);
        }

        public override void Update(GameTime gameTime)
        {
            var ms = Mouse.GetState();
            weaponItems.ForEach(w =>
            {
                if (!w.IsRemoved)
                {
                    var elem = (w as GraphicElement);
                    elem.PossitionX = this.PossitionX;
                    elem.PossitionY = this.PossitionY;
                    w.UpdateWeap(gameTime);
                }
            });
            if (ms.LeftButton == ButtonState.Pressed )
            {
                weaponItems.ForEach(w => { if (!w.IsRemoved)w.Shoot(gameTime); });
            }

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            MyGame.currentScreen.Draw(texture, Possition, Color.White);
            weaponItems.ForEach(w => { if (!w.IsRemoved) w.DrawWeap(gameTime); });
        }
    }
}
